using System;
using System.Data;
using NHibernate;
using NHibernate.Cfg;

namespace Serpis
{
	public class AppDbConnection
	{
		//Singleton
		private static AppDbConnection instance = new AppDbConnection();

		private AppDbConnection()
		{
		}
		
		public static AppDbConnection Instance {
			get {return instance;}
		}
		
		private Configuration configuration;
		
		public Configuration Configuration {
			get {
				if (configuration == null) {
					configuration= new Configuration();
					configuration.Configure();
				}
				return configuration;
			}
		}
		
		private ISessionFactory sessionFactory;
		
		public ISessionFactory SessionFactory {
			get {
				if (sessionFactory == null) 
					sessionFactory = configuration.BuildSessionFactory();
				return sessionFactory;
			}
		}
		
		public void Close()
		{
			sessionFactory.Close();
		}
	}
}
